//:C13:PStashTest.cpp
// {L} PStash
// Test of pointer Stash
#include "PStash.h"
#include "../require.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(void)
{
    PStash intStash;
    // 'new' works with built-in types, too. Note
    // the "pseudo-constructor" syntax:
    for(int i = 0; i < 25; i++)
    {
        intStash.add(new int(i));
    }

    for(int j = 0; j < intStash.count(); j++)
    {
        cout << "intStash[" << j << "] = "
             << *(int*)intStash[j] << endl;
    }
    // Clear up:
    for(int k = 0; k < intStash.count(); k++)
    {
        delete intStash.remove(k);
    }

    ifstream in("PStashTest.cpp");
    assure(in, "PStash.cpp");
    PStash stringStash;
    string line;
    while(getline(in, line))
    {
        stringStash.add(new string(line));
    }
    // Print out the strings:
    for(int u = 0; stringStash[u]; u++)
    {
        cout << "stringStash[" << u << "] = "
             << *(string*)stringStash[u] << endl;
    }
    // Clear up:
    for(int v = 0; v < stringStash.count(); v++)
    {
        delete (string*)stringStash.remove(v);
    }
}